/*----------------------------------------------------------------------------
 * osObjects.h: CMSIS-RTOS global object definitions for an application
 *----------------------------------------------------------------------------
 *
 * This header file defines global RTOS objects used throughout a project
 *
 * #define osObjectsPublic indicates that objects are defined; without that
 * definition the objects are defined as external symbols.
 *
 *--------------------------------------------------------------------------*/

#ifndef __os_obj__
#define __os_obj__

#ifdef __os_obj_creat__
#define OBJ_EXT
#else
#define OBJ_EXT extern
#endif

#include "stdint.h"

#ifdef __cplusplus
 extern "C" {
#endif
	 
#if OS_USED > 0
	 
#include "RTX_Config.h"
#include "cmsis_os.h" // CMSIS RTOS header file
	 
#define ms_ticks(x) ((x * OS_TICK_FREQ + 999) / 1000)
 
typedef struct
{
    // global 'thread' functions ---------------------------------------------------
    osThreadId tid_sys_task; // thread id
    osThreadId tid_usb_task; // thread id
    osThreadId tid_mb_task;  // thread id
    osThreadId tid_flash_task;
    osThreadId tid_str_task;
    osThreadId tid_gui_task;
    osThreadId tid_console_task;
	osThreadId tid_hist;
	osThreadId tid_dc_ui;
	osThreadId tid_ui_oled;
	osThreadId tid_par_save;
	
    // global 'semaphores' ----------------------------------------------------------
    osMutexId mid_eep;
    osMutexId mid_q25;
    osMutexId mid_printf;
    osMutexId mid_malloc;
    osMutexId mid_file;
	osMutexId mid_lcd;
	
    // global 'message queues' -------------------------------------------------------
	osMessageQId qid_par_save;
	
    // global 'mail queues' ----------------------------------------------------------

} os_obj_type;

OBJ_EXT os_obj_type os_obj;

#endif

int thread_init(void);
int thread_create(void);

void os_lock(void);
void os_unlock(void);

void os_task_info(void);

#ifdef __cplusplus
}
#endif

#endif // __os_obj__
